package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.domain.Shop;
import cn.wolfcode.crm.query.EmployeeQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.query.ShopQueryObject;
import cn.wolfcode.crm.serivce.IShopService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private IShopService service;

    @RequestMapping("view")
    public String view() throws Exception {
        return "shop";
    }

    @RequestMapping("listAll")
    @ResponseBody
    public List<Shop> listAll(QueryObject qo) throws Exception {
        List<Shop> shops = service.selectAll();
        return shops;
    }
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(ShopQueryObject qo) throws Exception {
        PageResult query = service.query(qo);
        return query;
    }
    @RequestMapping("deleteByPrimaryKey")
    @ResponseBody
    public JSONResult deleteByPrimaryKey(Long id) throws Exception {
       try {
        service.deleteByPrimaryKey(id);
        return new JSONResult();
       }catch (Exception e){
           e.printStackTrace();
           return new JSONResult().mark("删除失败");
       }

    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Shop shop) throws Exception {
        try {
            service.saveOrUpdate(shop);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("保存失败!");
        }
    }

}
